class Solution(object):
    def assignBikes(self, workers, bikes):
        """
        :type workers: List[List[int]]
        :type bikes: List[List[int]]
        :rtype: List[int]
        """
        n = len(workers)
        m = len(bikes)
        out = [-1] * n
        matches = []
        for i in range(n):
            for j in range(m):
                matches.append((abs(workers[i][0] - bikes[j][0]) + abs(workers[i][1] - bikes[j][1]), i, j))
        matches.sort(key=lambda x: (x[0], x[1], x[2]))
        already_bike = set()
        for item in matches:
            if out[item[1]] == -1 and item[2] not in already_bike:
                out[item[1]] = item[2]
                already_bike.add(item[2])
        return out


data = Solution()
workers = [[0, 0], [2, 1]]
bikes = [[1, 2], [3, 3]]
print(data.assignBikes(workers, bikes))
